//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: '',
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },

  buttons: { view: [], box: [], detail: [] },//扩展的按钮
  methods: {//事件扩展
    searchAfter (data) {
      if (data != null) {
        data.forEach((_, i) => {
          if (_.url != null) {
            if (_.url.indexOf('https://itownapi.boss.i-town.cn/') != -1) {
              data[i].url = data[i].url.replace('https://itownapi.boss.i-town.cn/', '')
            }
          }
        })
      }
      return true
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    getFormOption (field) {
      let option;
      this.editFormOptions.forEach((x) => {
        x.forEach((item) => {
          if (item.field == field) {
            option = item;
          }
        });
      });
      return option;
    },
    onInit () {
      let type = this.getFormOption('type')
      let url = this.getFormOption('url')
      let text = this.getFormOption('contractNoticetext')
      let list = [
        {
          key: 'img',
          value: '上传图片'
        },
        {
          key: 'text',
          value: '上传文件'
        },
      ]
      type.data = list;
      type.onChange = (n) => {
        if (n == 'img') {
          url.hidden = false
          text.hidden = true
          text.required = false
          this.editFormFields.contractNoticetext = ''
          url.required = true
        } else {
          text.hidden = false
          url.hidden = true
          this.editFormFields.url = ''
          url.required = false
          text.required = true
        }

      }
      this.columns.push({
        title: "操作",
        width: 165,
        render: (h, { row, column, index }) => {
          return h(
            "a",
            {
              props: {}, style: {},
              on: {
                click: () => {
                  let url = row.url
                  let urlPath = this.http.ipAddress + row.url
                  if (row.type == 'img') {
                    if (row.url != null) {
                      window.open( row.url.indexOf('https://oss.i-town.cn/') != -1 ? url : urlPath )
                    }
                    if (!url) {
                      this.$Message.error("还没有上传合同")
                    }
                  } else {
                    // console.log("合同文本")
                    this.linkData(row)
                  }
                }
              }
            },
            "查看合同"
          )
        }
      })
    },
    modelOpenAfter (row) {
      let isEDIT = this.currentAction == this.const.EDIT;
      let type = this.getFormOption('type')
      let url = this.getFormOption('url')
      let text = this.getFormOption('contractNoticetext')
      if (isEDIT) {
        // console.log("编辑")
        if (row.type == "img") {
          console.log("img")
          url.hidden = false
          text.hidden = true
          url.required = true
          text.required = false
        } else {
          console.log("text")
          text.hidden = false
          url.hidden = true
          url.required = false
          text.required = true
        }
      } else {
        url.hidden = true
        text.hidden = true
      }

    }
  }
};
export default extension;